package test.block;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Arat.Wu on 2018/05/24.
 */
public class Block {

    private static final Object object = new Object();
    static class Task implements Runnable{
        @Override
        public void run() {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService=Executors.newFixedThreadPool(10);
//        ScheduledExecutorService executorService2 = new ScheduledThreadPoolExecutor(10,
//                new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());
//        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
//                .setNameFormat("demo-pool-%d").build();
//
//        ExecutorService pool = new ThreadPoolExecutor(5, 200,
//                0L, TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

       // pool.execute(()-> System.out.println(Thread.currentThread().getName()));
       // pool.shutdown();//gracefully shutdown
        for(int i = 1; i<= 10; i++) {
            executorService.submit(new Task());
            //pool.execute(new Task());
            //pool.execute(new Task());

            //pool.shutdown();
            //Thread.sleep(1000);

        }
        //pool.shutdown();
    }

}
